#include <stdio.h>

static int j = 0;
do_child(int i)
{
	int pid;
	if (i < 2)
	{
		pid = fork();
		if(pid == -1)
			exit(0);
		else if(pid == 0)
		{
			do_child(i+1);
		} 
		else 
		{
			j++;
			printf("This is process %d, j=%d\n", i, j);
		}
	} 
	else 
	{
		j++;
		printf("This is process %d, j=%d\n", i, j);
	}
}

main()
{
	do_child(0);
}
